#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "hitten.h"
#include <QKeyEvent>
#include "QTime"
#include <QDebug>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::end ()//判断每一天是否到达冲鸭的状态
{
    for(int i=0;i<5;i++)
    {
        if(state[i]!=3)
            return;
    }
   this->close(); // test
    //目标达成，游戏结束//
}

void MainWindow::suijinum()  //生成随机数
{
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    for(int i=0; i<2; i++)  //随机改变两天的状态
    {
        int temp =qrand()%5+1;
        switch (temp) {
        case 1: ic1.index=qrand()%2; //第一天一般在快乐摸鱼，故状态0,1
            break;
        case 2: ic2.index=qrand()%3; //第二天或许因为罪恶感有想学习的欲望，故状态0,1,2
            break;
        case 3: ic3.index=qrand()%4; //后面几天因为确实没时间了,每天都有可能学习QT
            break;
        case 4: ic4.index=qrand()%4;
            break;
        case 5: ic5.index=qrand()%4;
            break;

        }
       // qDebug()<<temp;
    }
    gengxin();
}

void MainWindow::gengxin() //更新图片
{
    QPixmap g1(ic1.images[ic1.index]);
    ui->p1->setPixmap(g1);
    ui->p1->show();
    QPixmap g2(ic2.images[ic2.index]);
    ui->p2->setPixmap(g2);
    ui->p2->show();
    QPixmap g3(ic3.images[ic3.index]);
    ui->p3->setPixmap(g3);
    ui->p3->show();
    QPixmap g4(ic4.images[ic4.index]);
    ui->p4->setPixmap(g4);
    ui->p4->show();
    QPixmap g5(ic5.images[ic5.index]);
    ui->p5->setPixmap(g5);
    ui->p5->show();

}

void MainWindow::on_pushButton_1_clicked()
{
        QPixmap zou(ic1.NextImage());
        state[0]=ic1.index;
        //qDebug()<<ic1.index;
        ui->p1->setPixmap(zou);
        ui->p1->show();
        end ();
}

void MainWindow::on_pushButton_3_clicked()
{
    QPixmap zou(ic2.NextImage());
    state[1]=ic2.index;
    ui->p2->setPixmap(zou);
    ui->p2->show();
    suijinum();
}

void MainWindow::on_pushButton_5_clicked()
{
    QPixmap zou(ic3.NextImage());
    state[2]=ic3.index;
    ui->p3->setPixmap(zou);
    ui->p3->show();
}

void MainWindow::on_pushButton_clicked()
{
    QPixmap zou(ic4.NextImage());
    state[3]=ic4.index;
    ui->p4->setPixmap(zou);
    ui->p4->show();
}

void MainWindow::on_pushButton_2_clicked()
{
    QPixmap zou(ic5.NextImage());
    state[4]=ic5.index;
    ui->p5->setPixmap(zou);
    ui->p5->show();
}
